import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:happy_study/ui/shared/app_theme.dart';
import 'package:happy_study/ui/shared/image_assets.dart';

import 'login_logic.dart';

class LoginView extends StatelessWidget {
  final logic = Get.put(LoginLogic());
  final state = Get.find<LoginLogic>().state;
  static const String routeName = "/login";

  @override
  Widget build(BuildContext context) {
    return GetBuilder<LoginLogic>(builder: (logic) {
      return Scaffold(
        resizeToAvoidBottomInset: false,
        body: Stack(
          children: [
            buildLoginViewLoginBg(),
            Positioned(
              right: 10.r,
              top: 10.r,
              child: buildLoginViewRightButtons(),
            ),
            Positioned(
              bottom: 30.r,
              left: 0,
              right: 0,
              child: buildLoginViewLoginButton(),
            )
          ],
        ),
      );
    });
  }

  Widget buildLoginViewLoginBg() {
    return Container(
      width: 1.sw,
      height: 1.sh,
      decoration: BoxDecoration(
        image: DecorationImage(
            image: AssetImage(ImageAssets.loginBgPNG),
            fit: BoxFit.cover,
            filterQuality: FilterQuality.high),
      ),
    );
  }

  Widget buildLoginViewUserName() {
    return Text(
      state.isNeedCreateUser ? "" : state.user.userName,
      style: TextStyle(
        color: HYAppTheme.norWhite01Color,
        fontSize: 17.sp,
      ),
    );
  }

  Widget buildLoginViewLoginButton() {
    return Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        buildLoginViewUserName(),
        15.verticalSpace,
        InkWell(
          onTap: () {
            logic.clickLoginButton();
          },
          child: Container(
            decoration: BoxDecoration(
                color: HYAppTheme.norWhite01Color.withOpacity(.5),
                borderRadius: BorderRadius.all(Radius.circular(15.r))),
            padding: EdgeInsets.symmetric(horizontal: 25.r, vertical: 5.r),
            child: Text(
              "开始游戏",
              style: TextStyle(
                color: HYAppTheme.norTextColors,
                fontSize: 20.sp,
                fontWeight: FontWeight.bold,
              ),
            ),
          ),
        ),
      ],
    );
  }

  Widget buildLoginViewRightButtons() {
    return Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        buildLoginViewRightButton(ImageAssets.noticePNG),
        buildLoginViewRightButton(ImageAssets.accountPNG),
        buildLoginViewRightButton(ImageAssets.settingPNG),
      ],
    );
  }

  Widget buildLoginViewRightButton(image) {
    return Container(
      decoration: BoxDecoration(
        color: HYAppTheme.norWhite01Color,
        border: Border.all(
          color: HYAppTheme.norTextColors,
        ),
      ),
      child: Image.asset(
        image,
        width: 20.sp,
        height: 20.sp,
      ),
    );
  }
}
